]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
[StThemeNode] Don't give negative width/height for content boxes
authorColin Walters <walters@verbum.org>
Wed, 4 Nov 2009 20:48:26 +0000 (15:48 -0500)
committerColin Walters <walters@verbum.org>
Thu, 5 Nov 2009 20:28:56 +0000 (15:28 -0500)
If the space we're allocated is too small for our border + padding
constraints, don't give negative allocations to callers.  Squash
to zero.

It isn't really useful for callers to get negative content sizes,
and certainly breaks most allocation code.

https://bugzilla.gnome.org/show_bug.cgi?id=600734

src/st/st-theme-node.c

index 0aba8b6d5a5839e979caa31fea32109d79219acb..cebd1afdea1cc64791c2403cec133416c8c38162 100644 (file)
@@ -2211,14 +2211,33 @@ st_theme_node_get_content_box (StThemeNode           *node,
                                const ClutterActorBox *allocation,
                                ClutterActorBox       *content_box)
 {
+  double noncontent_left, noncontent_top, noncontent_right, noncontent_bottom;
+  double avail_width, avail_height, content_width, content_height;
+
   g_return_if_fail (ST_IS_THEME_NODE (node));
 
   ensure_geometry (node);
 
-  content_box->x1 = (int)(0.5 + node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT];
-  content_box->y1 = (int)(0.5 + node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP];
-  content_box->x2 = allocation->x2 - allocation->x1 - ((int)(0.5 + node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]);
-  content_box->y2 = allocation->y2 - allocation->y1 - ((int)(0.5 + node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]);
+  avail_width = allocation->x2 - allocation->x1;
+  avail_height = allocation->y2 - allocation->y1;
+
+  noncontent_left = node->border_width[ST_SIDE_LEFT] + node->padding[ST_SIDE_LEFT];
+  noncontent_top = node->border_width[ST_SIDE_TOP] + node->padding[ST_SIDE_TOP];
+  noncontent_right = node->border_width[ST_SIDE_RIGHT] + node->padding[ST_SIDE_RIGHT];
+  noncontent_bottom = node->border_width[ST_SIDE_BOTTOM] + node->padding[ST_SIDE_BOTTOM];
+
+  content_box->x1 = (int)(0.5 + noncontent_left);
+  content_box->y1 = (int)(0.5 + noncontent_top);
+
+  content_width = avail_width - noncontent_left - noncontent_right;
+  if (content_width < 0)
+    content_width = 0;
+  content_height = avail_height - noncontent_top - noncontent_bottom;
+  if (content_height < 0)
+    content_height = 0;
+
+  content_box->x2 = (int)(0.5 + content_box->x1 + content_width);
+  content_box->y2 = (int)(0.5 + content_box->y1 + content_height);
 }